import java.awt.CardLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class TestFullScreen {
	
	private static GraphicsDevice screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
	private static JFrame frame = new JFrame("TestFullScreen");
	private static Dimension screenSize = new Dimension(640,400);

	public static void createAndShowGUI() {
		frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setPreferredSize(screenSize);
		frame.setMinimumSize(screenSize);
		frame.setLayout(new CardLayout());

		Container container = frame.getContentPane();
		final JPanel panel1 = new JPanel(new GridLayout(2,1), true);
		final JPanel panel2 = new JPanel(new GridLayout(2,1), true);
		final JPanel panel3 = new JPanel(new GridLayout(2,1), true);
		JLabel label1 = new JLabel("PANEL 1", JLabel.CENTER);
		JLabel label2 = new JLabel("PANEL 2", JLabel.CENTER);
		JLabel label3 = new JLabel("PANEL 3", JLabel.CENTER);
		JButton button1 = new JButton("GO TO PANEL 2");
		JButton button2 = new JButton("GO TO PANEL 3");
		JButton button3 = new JButton("GO TO PANEL 1");
		
		// Panel 1
		panel1.setPreferredSize(screenSize);
		panel1.setBorder(BorderFactory.createLineBorder(null));
		button1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// Go to panel 2
				panel1.setVisible(false);
				panel2.setVisible(true);
			}
		});
		panel1.add(label1);
		panel1.add(button1);
		container.add(panel1);

		// Panel 2
		panel2.setPreferredSize(screenSize);
		panel2.setBorder(BorderFactory.createLineBorder(null));
		button2.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// Go to panel 3
				panel2.setVisible(false);
				panel3.setVisible(true);
			}
		});
		panel2.add(label2);
		panel2.add(button2);
		container.add(panel2);

		// Panel 3
		panel3.setPreferredSize(screenSize);
		panel3.setBorder(BorderFactory.createLineBorder(null));
		button3.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// Go to panel 1
				panel3.setVisible(false);
				panel1.setVisible(true);
			}
		});
		panel3.add(label3);
		panel3.add(button3);
		container.add(panel3);
		
		frame.pack();
		centerFrameWindow();
		frame.setVisible(true);
		screen.setFullScreenWindow(frame);
    }

	public static void centerFrameWindow() {
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		frame.setLocation(((int)dim.getWidth()-frame.getWidth())/2, ((int)dim.getHeight()-frame.getHeight())/2);
	}

	public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }

}
